<?php
/*
  $Id: column_products_listing.php $
  TomatoCart Open Source Shopping Cart Solutions
  http://www.tomatocart.com

  Copyright (c) 2009 Wuxi Elootec Technology Co., Ltd;  Copyright (c) 2007 osCommerce

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License v2 (1991)
  as published by the Free Software Foundation.
 */
/*
  Modified product_listing.php of TomatoCart
  Function: Display product list in column (taken from new_products listing model)
  Author: int2k
  Tested on TomatoCart V.1.1.1
  Updated: 2010/11/28

  USAGE:
1. Copy this file to includes/modules/
2. Edit your template content/index/product_listing.php
3. look for
   require('includes/modules/product_listing.php');
   replace it with
   require('includes/modules/col_products_listing.php');
   adapt the above path to suit your installation
this listing template can also be used for search result template
1. edit your template content/search/result.php
 look for
   require('includes/modules/product_listing.php');
   replace it with
   require('includes/modules/col_products_listing.php');
 */
?>
<?php

// create column list
$define_list = array('PRODUCT_LIST_SKU' => PRODUCT_LIST_SKU,
    'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
    'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
    'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
    'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
    'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
    'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE,
    'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);

asort($define_list);

$column_list = array();
reset($define_list);
while (list($key, $value) = each($define_list)) {
    if ($value > 0)
        $column_list[] = $key;
}

if (($Qlisting->numberOfRows() > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') )) {
?>

    <div class="listingPageLinks">
        <span style="float: right;"><?php echo $Qlisting->getBatchPageLinks('page', osc_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>

<?php echo $Qlisting->getBatchTotalPages($osC_Language->get('result_set_number_of_products')); ?>
</div>
<?php
}
?>
<?php
if ($Qlisting->numberOfRows() > 0) {
?>
<?php
    $avail_sorting = array();
    for ($col = 0, $n = sizeof($column_list); $col < $n; $col++) {
        $lc_key = false;
        $lc_align = 'center';

        switch ($column_list[$col]) {
            case 'PRODUCT_LIST_SKU':
                $lc_text = $osC_Language->get('listing_sku_heading');
                $lc_key = 'sku';
                break;
            case 'PRODUCT_LIST_NAME':
                $lc_text = $osC_Language->get('listing_products_heading');
                $lc_key = 'name';
                break;
            case 'PRODUCT_LIST_MANUFACTURER':
                $lc_text = $osC_Language->get('listing_manufacturer_heading');
                $lc_key = 'manufacturer';
                break;
            case 'PRODUCT_LIST_PRICE':
                $lc_text = $osC_Language->get('listing_price_heading');
                $lc_key = 'price';
                $lc_align = 'right';
                break;
            case 'PRODUCT_LIST_QUANTITY':
                $lc_text = $osC_Language->get('listing_quantity_heading');
                $lc_key = 'quantity';
                $lc_align = 'right';
                break;
            case 'PRODUCT_LIST_WEIGHT':
                $lc_text = $osC_Language->get('listing_weight_heading');
                $lc_key = 'weight';
                $lc_align = 'right';
                break;
            case 'PRODUCT_LIST_IMAGE':
                $lc_text = $osC_Language->get('listing_image_heading');
                $lc_align = 'center';
                break;
            case 'PRODUCT_LIST_BUY_NOW':
                $lc_text = $osC_Language->get('listing_buy_now_heading');
                $lc_align = 'center';
                break;
        }


        if ($lc_key !== false) {
            // Put sortable field into array
            $avail_sorting[] = array('id' => $lc_key, 'text' => $lc_text . ' (asc)');
            $avail_sorting[] = array('id' => $lc_key . '|d', 'text' => $lc_text . ' (desc)');
        }
    }

    $sort_heading = '<form name="sort" action="' . osc_href_link(basename($_SERVER['SCRIPT_FILENAME'])) . '" method="get">';
    $sort_heading .= osc_draw_pull_down_menu('sort', $avail_sorting, $_GET['sort'], ' onchange="this.form.submit()"');
    $params = explode('&', osc_get_all_get_params(array('page', 'sort')));
    foreach ($params as $key => $value) {
        $key_value = explode('=', $value);
        $sort_heading .= osc_draw_hidden_field($key_value[0], $key_value[1]);
    }
    $sort_heading .= '</form>';
?>
    <div class="moduleBox">
       <!-- <h6><span style="float: right;"><?php //echo $sort_heading; ?></span></h6>-->
        <div class="content">

<?php
    $rows = 0;
    $tcontent = '';
    while ($Qlisting->next()) {

       // if (($rows % 3 == 0) && ($rows != 0))
           // $tcontent .= '<div style="clear:both"></div>';
        $rows++;
        $tcontent .= '<div class="productItem" style="margin-top: 10px; float:left; text-align: center">';

        for ($col = 0, $n = sizeof($column_list); $col < $n; $col++) {
            $lc_align = '';
            $osC_Product = new osC_Product($Qlisting->value('products_id'));

            switch ($column_list[$col]) {
                case 'PRODUCT_LIST_SKU':
                    $lc_align = '';
                    $lc_text = '&nbsp;' . $Qlisting->value('products_sku') . '&nbsp;';
                    $tcontent .= '<span style="display:block; padding: 3px; text-align: center">' . $lc_text . '</span>';
                    break;
                case 'PRODUCT_LIST_NAME':
                    $lc_align = '';
                    if (isset($_GET['manufacturers'])) {
                        $lc_text = osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qlisting->value('products_id') . '&manufacturers=' . $_GET['manufacturers']), $Qlisting->value('products_name')) . (($Qlisting->value('products_short_description') === NULL) || ($Qlisting->value('products_short_description') === '') ? '' : '');//'<p>' . $Qlisting->value('products_short_description') . '</p>'); //tiennm
                    } else {
                        $lc_text = '&nbsp;' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qlisting->value('products_id') . ($cPath ? '&cPath=' . $cPath : '')), $Qlisting->value('products_name')) . (($Qlisting->value('products_short_description') === NULL) || ($Qlisting->value('products_short_description') === '') ? '' : '');//'<p>' . $Qlisting->value('products_short_description') . '</p>') . '&nbsp;'; //tiennm
                    }
                    $tcontent .= '<span class="productName" >' . $lc_text . '</span>';
                    break;
                case 'PRODUCT_LIST_MANUFACTURER':
                    $lc_align = '';
                    $lc_text = '&nbsp;' . osc_link_object(osc_href_link(FILENAME_DEFAULT, 'manufacturers=' . $Qlisting->valueInt('manufacturers_id')), $Qlisting->value('manufacturers_name')) . '&nbsp;';
                    $tcontent .= '<span style="display:block; padding: 3px; text-align: center">' . $lc_text . '</span>';
                    break;
                case 'PRODUCT_LIST_PRICE':
                    $lc_align = 'right';
                    $lc_text = $osC_Product->getPriceFormated(true);
                    $tcontent .= '<span  class="productPrice" >' . $lc_text . '</span>';
                    break;
                case 'PRODUCT_LIST_QUANTITY':
                    $lc_align = 'right';
                    $lc_text = '&nbsp;' . $Qlisting->valueInt('products_quantity') . '&nbsp;';
                    $tcontent .= '<span style="display:block; height: 32px; text-align: center">' . $lc_text . '</span>';
                    break;
                case 'PRODUCT_LIST_WEIGHT':
                    $lc_align = 'right';
                    $lc_text = '&nbsp;' . $osC_Weight->display($Qlisting->value('products_weight'), $Qlisting->value('products_weight_class')) . '&nbsp;';
                    $tcontent .= '<span style="display:block; padding: 3px; text-align: center">' . $lc_text . '</span>';
                    break;
                case 'PRODUCT_LIST_IMAGE':
                    $lc_align = 'center';
                    if (isset($_GET['manufacturers'])) {
                        if ($Qlisting->value('products_type') == PRODUCT_TYPE_SIMPLE) {
                            $lc_text = osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qlisting->value('products_id') . '&manufacturers=' . $_GET['manufacturers']), $osC_Image->show($Qlisting->value('image'), $Qlisting->value('products_name')), 'id="productImage' . $Qlisting->value('products_id') . '"');
                        } else {
                            $lc_text = osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qlisting->value('products_id') . '&manufacturers=' . $_GET['manufacturers']), $osC_Image->show($Qlisting->value('image'), $Qlisting->value('products_name')));
                        }
                    } else {
                        if ($Qlisting->value('products_type') == PRODUCT_TYPE_SIMPLE) {
                            $lc_text = osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qlisting->value('products_id') . ($cPath ? '&cPath=' . $cPath : '')), $osC_Image->show($Qlisting->value('image'), $Qlisting->value('products_name')), 'id="productImage' . $Qlisting->value('products_id') . '"');
                        } else {
                            $lc_text = osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qlisting->value('products_id') . ($cPath ? '&cPath=' . $cPath : '')), $osC_Image->show($Qlisting->value('image'), $Qlisting->value('products_name')));
                        }
                    }
                    $tcontent .= $lc_text;
                    break;
                case 'PRODUCT_LIST_BUY_NOW':
                    $lc_align = 'center';
                    if ($Qlisting->value('products_type') == PRODUCT_TYPE_SIMPLE) {
                        $lc_text =  
							 osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qlisting->valueInt('products_id')), osc_draw_image_button('small_read_more.png', $osC_Language->get('small_read_more'), 'id="productImage' . $Qlisting->value('products_id') . '"')).osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_add_to_cart.png', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_productlisting_' . $Qlisting->value('products_id') . '"')) . '&nbsp;<br />';
                    } else {
                        $lc_text = osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_add_to_cart.png', $osC_Language->get('button_add_to_cart'))) . '&nbsp;<br />';
                    }
                    $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=compare_products_add'), $osC_Language->get('add_to_compare')) . '&nbsp;<br />';
                    $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=wishlist_add'), $osC_Language->get('add_to_wishlist'));
                    $tcontent .= '<span style="display:block; padding: 3px; text-align: center">' . $lc_text . '</span>';
                    break;
            }


            //echo '      <td ' . ((empty($lc_align) === false) ? 'align="' . $lc_align . '" ' : '') . ' valign="top" class="productListing-data">' . $lc_text . '</td>' . "\n";
        }
        $tcontent .= '</div>';

//      echo '    </tr>' . "\n";
    }
?>
<?php
    echo $tcontent;
?>      <div style="clear:both"></div>
    </div>
</div>
        
<?php
} else {
    echo $osC_Language->get('no_products_in_category');
}
?>

<?php
if (($Qlisting->numberOfRows() > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>

    <div class="listingPageLinks">
        <span style="float: right;"><?php echo $Qlisting->getBatchPageLinks('page', osc_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
<?php echo $Qlisting->getBatchTotalPages($osC_Language->get('result_set_number_of_products')); ?>
    </div>

<?php
}
?>